package com.example.tests;
import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase {
	@Test (dataProvider = "randomValidContactGenerator")
	public void testContactCreationWithValidData(ContactData contact) throws Exception {
		app.getContactHelper().goToMainPage();
		
		
		// save old state
		List<ContactData> oldList = app.getContactHelper().getContacts();
		
		//actions
		app.getContactHelper().goToCreateContactPage();
		app.getContactHelper().fillContactCreationForms(contact, true);
		app.getContactHelper().submitContact();
		app.getContactHelper().goBackToMainPage();
		
		//save new state
		List<ContactData> newList = app.getContactHelper().getContacts();
	
		//compare states
		oldList.add(contact);
		Collections.sort(oldList);
		assertEquals(newList, oldList);

	}
	//@Test
	public void testEmptyContactCreation() throws Exception {
		app.getContactHelper().goToMainPage();
		app.getContactHelper().goToCreateContactPage();
		ContactData contact = new ContactData();
		contact.firstname = "";
		contact.lastname = "";
		contact.address = "";
		contact.homephone = "";
		contact.mobilephone = "";
		contact.workphone = "";
		contact.email1 = "";
		contact.email2 = "";
		contact.birthday = "-";
		contact.birthmonth = "-";
		contact.birthyear = "";
		contact.groupselect = "";
		contact.address2 = "";
		contact.home = "";
		app.getContactHelper().fillContactCreationForms(contact, true);		
		app.getContactHelper().submitContact();
		app.getContactHelper().goBackToMainPage();
	}
}
